package org.jflame.commons.crypto.digest;

import org.jflame.commons.crypto.KeyAlgName;
import org.jflame.commons.util.StringHelper;

/**
 * 常用数字签名算法名枚举
 * <p>
 * 不常用的签名算法不在此枚举内,但可以以字符串方法自行组合,算法名通用格式:
 * 
 * <pre>
 *  {@code <digest>with<encryption> }</pre>
 * 
 * digest为摘要算法名 encryption可以是非对称加密算法RSA/DSA/ECDSA等
 * <p>
 * 详情查看: {@link <a href=
 * "https://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html#Signature">官方文档</a> }
 * 
 * @author charles.zhang
 */
public enum SignatureAlg implements KeyAlgName {

    MD5withRSA,
    SHA1withRSA,
    SHA256withRSA,
    SHA1withDSA,
    SHA256withDSA,
    SHA512withDSA,
    SHA256withECDSA,
    SHA512withECDSA,
    SM3withSM2;

    @Override
    public String keyAlgorithm() {
        String alg = StringHelper.substringAfter(this.name(), "with");
        if ("ECDSA".equals(alg) || "SM2".equals(alg)) {
            return "EC";
        } else {
            return alg;
        }
    }
}
